﻿using System;

namespace Terraria.GameContent.Achievements
{
	// Token: 0x02000460 RID: 1120
	public class AchievementsHelper
	{
		// Token: 0x1400003D RID: 61
		// (add) Token: 0x0600261F RID: 9759 RVA: 0x00490BA8 File Offset: 0x0048EDA8
		// (remove) Token: 0x06002620 RID: 9760 RVA: 0x00490BDC File Offset: 0x0048EDDC
		public static event AchievementsHelper.ItemPickupEvent OnItemPickup;

		// Token: 0x1400003E RID: 62
		// (add) Token: 0x06002621 RID: 9761 RVA: 0x00490C10 File Offset: 0x0048EE10
		// (remove) Token: 0x06002622 RID: 9762 RVA: 0x00490C44 File Offset: 0x0048EE44
		public static event AchievementsHelper.ItemCraftEvent OnItemCraft;

		// Token: 0x1400003F RID: 63
		// (add) Token: 0x06002623 RID: 9763 RVA: 0x00490C78 File Offset: 0x0048EE78
		// (remove) Token: 0x06002624 RID: 9764 RVA: 0x00490CAC File Offset: 0x0048EEAC
		public static event AchievementsHelper.TileDestroyedEvent OnTileDestroyed;

		// Token: 0x14000040 RID: 64
		// (add) Token: 0x06002625 RID: 9765 RVA: 0x00490CE0 File Offset: 0x0048EEE0
		// (remove) Token: 0x06002626 RID: 9766 RVA: 0x00490D14 File Offset: 0x0048EF14
		public static event AchievementsHelper.NPCKilledEvent OnNPCKilled;

		// Token: 0x14000041 RID: 65
		// (add) Token: 0x06002627 RID: 9767 RVA: 0x00490D48 File Offset: 0x0048EF48
		// (remove) Token: 0x06002628 RID: 9768 RVA: 0x00490D7C File Offset: 0x0048EF7C
		public static event AchievementsHelper.ProgressionEventEvent OnProgressionEvent;

		// Token: 0x170002A8 RID: 680
		// (get) Token: 0x06002629 RID: 9769 RVA: 0x0001A8CE File Offset: 0x00018ACE
		// (set) Token: 0x0600262A RID: 9770 RVA: 0x0001A8D5 File Offset: 0x00018AD5
		public static bool CurrentlyMining
		{
			get
			{
				return AchievementsHelper._isMining;
			}
			set
			{
				AchievementsHelper._isMining = value;
			}
		}

		// Token: 0x0600262B RID: 9771 RVA: 0x0001A8DD File Offset: 0x00018ADD
		public static void NotifyTileDestroyed(Player player, ushort tile)
		{
			if (Main.gameMenu || !AchievementsHelper._isMining)
			{
				return;
			}
			if (AchievementsHelper.OnTileDestroyed != null)
			{
				AchievementsHelper.OnTileDestroyed(player, tile);
			}
		}

		// Token: 0x0600262C RID: 9772 RVA: 0x0001A901 File Offset: 0x00018B01
		public static void NotifyItemPickup(Player player, Item item)
		{
			if (AchievementsHelper.OnItemPickup != null)
			{
				AchievementsHelper.OnItemPickup(player, (short)item.netID, item.stack);
			}
		}

		// Token: 0x0600262D RID: 9773 RVA: 0x0001A922 File Offset: 0x00018B22
		public static void NotifyItemPickup(Player player, Item item, int customStack)
		{
			if (AchievementsHelper.OnItemPickup != null)
			{
				AchievementsHelper.OnItemPickup(player, (short)item.netID, customStack);
			}
		}

		// Token: 0x0600262E RID: 9774 RVA: 0x0001A93E File Offset: 0x00018B3E
		public static void NotifyItemCraft(Recipe recipe)
		{
			if (AchievementsHelper.OnItemCraft != null)
			{
				AchievementsHelper.OnItemCraft((short)recipe.createItem.netID, recipe.createItem.stack);
			}
		}

		// Token: 0x0600262F RID: 9775 RVA: 0x0001A968 File Offset: 0x00018B68
		public static void Initialize()
		{
			Player.Hooks.OnEnterWorld += AchievementsHelper.OnPlayerEnteredWorld;
		}

		// Token: 0x06002630 RID: 9776 RVA: 0x00490DB0 File Offset: 0x0048EFB0
		private static void OnPlayerEnteredWorld(Player player)
		{
			if (AchievementsHelper.OnItemPickup != null)
			{
				for (int i = 0; i < 58; i++)
				{
					AchievementsHelper.OnItemPickup(player, (short)player.inventory[i].type, player.inventory[i].stack);
				}
				for (int j = 0; j < player.armor.Length; j++)
				{
					AchievementsHelper.OnItemPickup(player, (short)player.armor[j].type, player.armor[j].stack);
				}
				for (int k = 0; k < player.dye.Length; k++)
				{
					AchievementsHelper.OnItemPickup(player, (short)player.dye[k].type, player.dye[k].stack);
				}
				for (int l = 0; l < player.miscEquips.Length; l++)
				{
					AchievementsHelper.OnItemPickup(player, (short)player.miscEquips[l].type, player.miscEquips[l].stack);
				}
				for (int m = 0; m < player.miscDyes.Length; m++)
				{
					AchievementsHelper.OnItemPickup(player, (short)player.miscDyes[m].type, player.miscDyes[m].stack);
				}
				for (int n = 0; n < player.bank.item.Length; n++)
				{
					AchievementsHelper.OnItemPickup(player, (short)player.bank.item[n].type, player.bank.item[n].stack);
				}
				for (int num = 0; num < player.bank2.item.Length; num++)
				{
					AchievementsHelper.OnItemPickup(player, (short)player.bank2.item[num].type, player.bank2.item[num].stack);
				}
				for (int num2 = 0; num2 < player.bank3.item.Length; num2++)
				{
					AchievementsHelper.OnItemPickup(player, (short)player.bank3.item[num2].type, player.bank3.item[num2].stack);
				}
			}
			if (player.statManaMax > 20)
			{
				Main.Achievements.GetCondition("STAR_POWER", "Use").Complete();
			}
			if (player.statLifeMax == 500 && player.statManaMax == 200)
			{
				Main.Achievements.GetCondition("TOPPED_OFF", "Use").Complete();
			}
			if (player.miscEquips[4].type > 0)
			{
				Main.Achievements.GetCondition("HOLD_ON_TIGHT", "Equip").Complete();
			}
			if (player.miscEquips[3].type > 0)
			{
				Main.Achievements.GetCondition("THE_CAVALRY", "Equip").Complete();
			}
			for (int num3 = 0; num3 < player.armor.Length; num3++)
			{
				if (player.armor[num3].wingSlot > 0)
				{
					Main.Achievements.GetCondition("HEAD_IN_THE_CLOUDS", "Equip").Complete();
					break;
				}
			}
			if (player.armor[0].stack > 0 && player.armor[1].stack > 0 && player.armor[2].stack > 0)
			{
				Main.Achievements.GetCondition("MATCHING_ATTIRE", "Equip").Complete();
			}
			if (player.armor[10].stack > 0 && player.armor[11].stack > 0 && player.armor[12].stack > 0)
			{
				Main.Achievements.GetCondition("FASHION_STATEMENT", "Equip").Complete();
			}
			bool flag = true;
			for (int num4 = 0; num4 < player.extraAccessorySlots + 3 + 5; num4++)
			{
				if (player.dye[num4].type < 1 || player.dye[num4].stack < 1)
				{
					flag = false;
				}
			}
			if (flag)
			{
				Main.Achievements.GetCondition("DYE_HARD", "Equip").Complete();
			}
		}

		// Token: 0x06002631 RID: 9777 RVA: 0x004911B0 File Offset: 0x0048F3B0
		public static void NotifyNPCKilled(NPC npc)
		{
			if (Main.netMode == 0)
			{
				if (npc.playerInteraction[Main.myPlayer])
				{
					AchievementsHelper.NotifyNPCKilledDirect(Main.player[Main.myPlayer], npc.netID);
					return;
				}
			}
			else
			{
				for (int i = 0; i < 255; i++)
				{
					if (npc.playerInteraction[i])
					{
						NetMessage.SendData(97, i, -1, null, npc.netID, 0f, 0f, 0f, 0, 0, 0);
					}
				}
			}
		}

		// Token: 0x06002632 RID: 9778 RVA: 0x0001A97B File Offset: 0x00018B7B
		public static void NotifyNPCKilledDirect(Player player, int npcNetID)
		{
			if (AchievementsHelper.OnNPCKilled != null)
			{
				AchievementsHelper.OnNPCKilled(player, (short)npcNetID);
			}
		}

		// Token: 0x06002633 RID: 9779 RVA: 0x00491228 File Offset: 0x0048F428
		public static void NotifyProgressionEvent(int eventID)
		{
			if (Main.netMode == 2)
			{
				NetMessage.SendData(98, -1, -1, null, eventID, 0f, 0f, 0f, 0, 0, 0);
				return;
			}
			if (AchievementsHelper.OnProgressionEvent != null)
			{
				AchievementsHelper.OnProgressionEvent(eventID);
			}
		}

		// Token: 0x06002634 RID: 9780 RVA: 0x00491270 File Offset: 0x0048F470
		public static void HandleOnEquip(Player player, Item item, int context)
		{
			if (context == 16)
			{
				Main.Achievements.GetCondition("HOLD_ON_TIGHT", "Equip").Complete();
			}
			if (context == 17)
			{
				Main.Achievements.GetCondition("THE_CAVALRY", "Equip").Complete();
			}
			if ((context == 10 || context == 11) && item.wingSlot > 0)
			{
				Main.Achievements.GetCondition("HEAD_IN_THE_CLOUDS", "Equip").Complete();
			}
			if (context == 8 && player.armor[0].stack > 0 && player.armor[1].stack > 0 && player.armor[2].stack > 0)
			{
				Main.Achievements.GetCondition("MATCHING_ATTIRE", "Equip").Complete();
			}
			if (context == 9 && player.armor[10].stack > 0 && player.armor[11].stack > 0 && player.armor[12].stack > 0)
			{
				Main.Achievements.GetCondition("FASHION_STATEMENT", "Equip").Complete();
			}
			if (context == 12)
			{
				for (int i = 0; i < player.extraAccessorySlots + 3 + 5; i++)
				{
					if (player.dye[i].type < 1 || player.dye[i].stack < 1)
					{
						return;
					}
				}
				for (int j = 0; j < player.miscDyes.Length; j++)
				{
					if (player.miscDyes[j].type < 1 || player.miscDyes[j].stack < 1)
					{
						return;
					}
				}
				Main.Achievements.GetCondition("DYE_HARD", "Equip").Complete();
			}
		}

		// Token: 0x06002635 RID: 9781 RVA: 0x00491410 File Offset: 0x0048F610
		public static void HandleSpecialEvent(Player player, int eventID)
		{
			if (player.whoAmI != Main.myPlayer)
			{
				return;
			}
			switch (eventID)
			{
			case 1:
				Main.Achievements.GetCondition("STAR_POWER", "Use").Complete();
				if (player.statLifeMax == 500 && player.statManaMax == 200)
				{
					Main.Achievements.GetCondition("TOPPED_OFF", "Use").Complete();
					return;
				}
				break;
			case 2:
				Main.Achievements.GetCondition("GET_A_LIFE", "Use").Complete();
				if (player.statLifeMax == 500 && player.statManaMax == 200)
				{
					Main.Achievements.GetCondition("TOPPED_OFF", "Use").Complete();
					return;
				}
				break;
			case 3:
				Main.Achievements.GetCondition("NOT_THE_BEES", "Use").Complete();
				return;
			case 4:
				Main.Achievements.GetCondition("WATCH_YOUR_STEP", "Hit").Complete();
				return;
			case 5:
				Main.Achievements.GetCondition("RAINBOWS_AND_UNICORNS", "Use").Complete();
				return;
			case 6:
				Main.Achievements.GetCondition("YOU_AND_WHAT_ARMY", "Spawn").Complete();
				return;
			case 7:
				Main.Achievements.GetCondition("THROWING_LINES", "Use").Complete();
				return;
			case 8:
				Main.Achievements.GetCondition("LUCKY_BREAK", "Hit").Complete();
				return;
			case 9:
				Main.Achievements.GetCondition("VEHICULAR_MANSLAUGHTER", "Hit").Complete();
				return;
			case 10:
				Main.Achievements.GetCondition("ROCK_BOTTOM", "Reach").Complete();
				return;
			case 11:
				Main.Achievements.GetCondition("INTO_ORBIT", "Reach").Complete();
				return;
			case 12:
				Main.Achievements.GetCondition("WHERES_MY_HONEY", "Reach").Complete();
				return;
			case 13:
				Main.Achievements.GetCondition("JEEPERS_CREEPERS", "Reach").Complete();
				return;
			case 14:
				Main.Achievements.GetCondition("ITS_GETTING_HOT_IN_HERE", "Reach").Complete();
				return;
			case 15:
				Main.Achievements.GetCondition("FUNKYTOWN", "Reach").Complete();
				return;
			case 16:
				Main.Achievements.GetCondition("I_AM_LOOT", "Peek").Complete();
				return;
			default:
				return;
			}
		}

		// Token: 0x06002636 RID: 9782 RVA: 0x00491688 File Offset: 0x0048F888
		public static void HandleNurseService(int coinsSpent)
		{
			CustomFloatCondition customFloatCondition = (CustomFloatCondition)Main.Achievements.GetCondition("FREQUENT_FLYER", "Pay");
			customFloatCondition.Value += (float)coinsSpent;
		}

		// Token: 0x06002637 RID: 9783 RVA: 0x004916C0 File Offset: 0x0048F8C0
		public static void HandleAnglerService()
		{
			Main.Achievements.GetCondition("SERVANT_IN_TRAINING", "Finish").Complete();
			CustomIntCondition customIntCondition = (CustomIntCondition)Main.Achievements.GetCondition("GOOD_LITTLE_SLAVE", "Finish");
			int value = customIntCondition.Value;
			customIntCondition.Value = value + 1;
			CustomIntCondition customIntCondition2 = (CustomIntCondition)Main.Achievements.GetCondition("TROUT_MONKEY", "Finish");
			value = customIntCondition2.Value;
			customIntCondition2.Value = value + 1;
			CustomIntCondition customIntCondition3 = (CustomIntCondition)Main.Achievements.GetCondition("FAST_AND_FISHIOUS", "Finish");
			value = customIntCondition3.Value;
			customIntCondition3.Value = value + 1;
			CustomIntCondition customIntCondition4 = (CustomIntCondition)Main.Achievements.GetCondition("SUPREME_HELPER_MINION", "Finish");
			value = customIntCondition4.Value;
			customIntCondition4.Value = value + 1;
		}

		// Token: 0x06002638 RID: 9784 RVA: 0x0001A991 File Offset: 0x00018B91
		public static void HandleRunning(float pixelsMoved)
		{
			((CustomFloatCondition)Main.Achievements.GetCondition("MARATHON_MEDALIST", "Move")).Value += pixelsMoved;
		}

		// Token: 0x06002639 RID: 9785 RVA: 0x00491788 File Offset: 0x0048F988
		public static void HandleMining()
		{
			CustomIntCondition customIntCondition = (CustomIntCondition)Main.Achievements.GetCondition("BULLDOZER", "Pick");
			int value = customIntCondition.Value;
			customIntCondition.Value = value + 1;
		}

		// Token: 0x0600263A RID: 9786 RVA: 0x004917C0 File Offset: 0x0048F9C0
		public static void CheckMechaMayhem(int justKilled = -1)
		{
			if (!AchievementsHelper.mayhemOK)
			{
				if (NPC.AnyNPCs(127) && NPC.AnyNPCs(134) && NPC.AnyNPCs(126) && NPC.AnyNPCs(125))
				{
					AchievementsHelper.mayhemOK = true;
					AchievementsHelper.mayhem1down = false;
					AchievementsHelper.mayhem2down = false;
					AchievementsHelper.mayhem3down = false;
					return;
				}
			}
			else
			{
				if (justKilled == 125 || justKilled == 126)
				{
					AchievementsHelper.mayhem1down = true;
				}
				else if (!NPC.AnyNPCs(125) && !NPC.AnyNPCs(126) && !AchievementsHelper.mayhem1down)
				{
					AchievementsHelper.mayhemOK = false;
					return;
				}
				if (justKilled == 134)
				{
					AchievementsHelper.mayhem2down = true;
				}
				else if (!NPC.AnyNPCs(134) && !AchievementsHelper.mayhem2down)
				{
					AchievementsHelper.mayhemOK = false;
					return;
				}
				if (justKilled == 127)
				{
					AchievementsHelper.mayhem3down = true;
				}
				else if (!NPC.AnyNPCs(127) && !AchievementsHelper.mayhem3down)
				{
					AchievementsHelper.mayhemOK = false;
					return;
				}
				if (AchievementsHelper.mayhem1down && AchievementsHelper.mayhem2down && AchievementsHelper.mayhem3down)
				{
					AchievementsHelper.NotifyProgressionEvent(21);
				}
			}
		}

		// Token: 0x0400418F RID: 16783
		private static bool _isMining;

		// Token: 0x04004190 RID: 16784
		private static bool mayhemOK;

		// Token: 0x04004191 RID: 16785
		private static bool mayhem1down;

		// Token: 0x04004192 RID: 16786
		private static bool mayhem2down;

		// Token: 0x04004193 RID: 16787
		private static bool mayhem3down;

		// Token: 0x02000461 RID: 1121
		// (Invoke) Token: 0x0600263E RID: 9790
		public delegate void ItemPickupEvent(Player player, short itemId, int count);

		// Token: 0x02000462 RID: 1122
		// (Invoke) Token: 0x06002642 RID: 9794
		public delegate void ItemCraftEvent(short itemId, int count);

		// Token: 0x02000463 RID: 1123
		// (Invoke) Token: 0x06002646 RID: 9798
		public delegate void TileDestroyedEvent(Player player, ushort tileId);

		// Token: 0x02000464 RID: 1124
		// (Invoke) Token: 0x0600264A RID: 9802
		public delegate void NPCKilledEvent(Player player, short npcId);

		// Token: 0x02000465 RID: 1125
		// (Invoke) Token: 0x0600264E RID: 9806
		public delegate void ProgressionEventEvent(int eventID);
	}
}
